class AsyncPromise {
    constructor() {
        this.promise=null;
        this.events={};
    }

    createrPromise() {
        this.promise=new Promise((resolve,reject)=>{
            this.resolve=resolve;
            this.reject=reject;
        })
        return this.promise
    }


    on(event, callback) {
        if(!this.events[event]){
            this.events[event] = [];
        }
        this.events[event].push(callback);
    }


    emit(event, data) {
        if(this.events[event]){
            this.events[event].forEach(callback=>callback(data));
        }

    }

    async rsolve(success){
        this.emit('success', success);
        this.resolve(success)
    }

    async reject(error){
        this.emit('error', error);
        this.reject(error);
    }
}


async function example(){
    const asyncPromise=new AsyncPromise();
    const promise=asyncPromise.createrPromise();
    asyncPromise.on('success',success=>{
        console.log('success---',success);
    })

    asyncPromise.on('error',error=>{
        console.log('error---',error);
    })


    promise.then(function (resolve) {
        console.log('prmose----resolve---',resolve);
    }).catch(reject=>{
        console.log('prmose----reject---',reject);
    })


    await asyncPromise.resolve('hello world----e');
}


example();